package edu.scau.comeva.rigcontrol.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

/**
 * Created with IntelliJ IDEA.
 * User: Dan
 * Date: 13-8-15
 * Time: 下午10:46
 * To change this template use File | Settings | File Templates.
 */
public class HibernateAnnotacionUitl {
    private static SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory() {
        try{
            Configuration configuration = new AnnotationConfiguration().configure();
            sessionFactory = configuration.buildSessionFactory();
            return sessionFactory;
        }catch (Throwable e){
            System.err.println("Initial SessionFactory creation failed." + e);
            throw new ExceptionInInitializerError(e);
        }
    }

    public static SessionFactory getSessionFactory(){
        return sessionFactory;
    }
}
